function [out,out2]=demodulation(ym, M, N)
    length = size(ym, 2);
    symbols = length / (N + M);
    out = zeros(1, symbols * N);
    for i=0:symbols-1
        for k=0:N-1
            sum = 0;
            for m=0:N-1
                sum = sum + ym(i * (M+N) + M + m+1) * exp(-1j*2*pi*k*m/N);
            end
            out(i*N + k+1) = sum / sqrt(N);
        end
    end
    
    ym = ym(M+1:M+N);
    out2 = zeros(1, 64);
    for k=0:N-1
        sum = 0;
        for m=0:N-1
            sum = sum + ym(m+1) * exp(-1j*2*pi*k*m/N);
        end
        out2(k+1) = sum / sqrt(N);
    end
end